package com.ruoyi.web.controller.zhuangxiucontroller.shopController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.PreferentialCard;
import com.ruoyi.system.service.zhaungxiuservice.shopService.PreferentialCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商家优惠卷Controller
 *赵德健
 * @author ruoyi
 * @date 2020-12-17
 */
@RestController
@RequestMapping("/preferen/card")
public class PreferentialCardController extends BaseController {

    @Autowired(required = false)
    private PreferentialCardService preferentialCardService;


    /**
     * 查询优惠卷列表
     */
    @PreAuthorize("@ss.hasPermi('preferen:card:list')")
    @GetMapping("/list/{supplierId}")
    public List<PreferentialCard> list(@PathVariable("supplierId") Integer supplierId)
    {
        return preferentialCardService.selectPreferentialCardList(supplierId);
    }

    /**
     * 导出优惠卷列表
     */
//    @PreAuthorize("@ss.hasPermi('preferen:card:export')")
//    @Log(title = "优惠卷", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(PreferentialCard preferentialCard)
//    {
//        List<PreferentialCard> list = preferentialCardService.selectPreferentialCardList(preferentialCard);
//        ExcelUtil<PreferentialCard> util = new ExcelUtil<PreferentialCard>(PreferentialCard.class);
//        return util.exportExcel(list, "card");
//    }

    /**
     * 获取优惠卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('preferen:card:query')")
    @GetMapping(value = "/{preferentialId}")
    public AjaxResult getInfo(@PathVariable("preferentialId") Integer preferentialId)
    {
        return AjaxResult.success(preferentialCardService.selectPreferentialCardById(preferentialId));
    }

    /**
     * 新增优惠卷
     */
    @PreAuthorize("@ss.hasPermi('preferen:card:add')")
    @Log(title = "优惠卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PreferentialCard preferentialCard)
    {
        return toAjax(preferentialCardService.insertPreferentialCard(preferentialCard));
    }

    /**
     * 修改优惠卷
     */
    @PreAuthorize("@ss.hasPermi('preferen:card:edit')")
    @Log(title = "优惠卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PreferentialCard preferentialCard)
    {
        return toAjax(preferentialCardService.updatePreferentialCard(preferentialCard));
    }

    /**
     * 删除优惠卷
     */
    @PreAuthorize("@ss.hasPermi('preferen:card:remove')")
    @Log(title = "优惠卷", businessType = BusinessType.DELETE)
    @DeleteMapping("/{preferentialIds}")
    public AjaxResult remove(@PathVariable Integer[] preferentialIds)
    {
        return toAjax(preferentialCardService.deletePreferentialCardByIds(preferentialIds));
    }


}
